<?php
  session_cache_limiter('private,must-revalide');
   /**
   * 处理上传页面
   */ 
  if ($_POST['btn_sub'])
  {
    include($conf["base_path"] ."lib/thumbnail.php");
	$cate_id = intval( $_POST["cate_id"] ); //分类
	if (empty($cate_id))
	{
	   MyNotice("請選擇分類");
	   exit(0);
	} 

	for($i=1;$i<=30;$i++)
		{
			$furniturex ="furniture".$i;
			$furniturex2 = $_POST[$furniturex];
			if($furniturex2!='')
			{
				if($furniture=='')
				{
					$furniture = $furniturex2;
				}else{
					$furniture = $furniturex2.' / '.$furniture;
				}
			}
			$wiringx ="wiring".$i;
			$wiringx2 = $_POST[$wiringx];
			if($wiringx2!='')
			{
				if($wiring=='')
				{
					$wiring = $wiringx2;
				}else{
					$wiring=$wiringx2.' / '.$wiring;
				}
			}
			$baohangx ="baohang".$i;
			$baohangx2 = $_POST[$baohangx];
			if($baohangx2!='')
			{
				if($baohang=='')
				{
					$baohang = $baohangx2;
				}else{
					$baohang=$baohangx2.' / '.$baohang;
				}
			}
			$firex ="fire".$i;
			$firex2 = $_POST[$firex];
			if($firex2!='')
			{
				if($fire=='')
				{
					$fire = $firex2;
				}else{
					$fire=$firex2.' / '.$fire;
				}
			}
			$baoquanx ="baoquan".$i;
			$baoquanx2 = $_POST[$baoquanx];
			if($baoquanx2!='')
			{
				if($baoquan=='')
				{
					$baoquan = $baoquanx2;
				}else{
					$baoquan=$baoquanx2.' / '.$baoquan;
				}
			}
		}

	$query1 = "SELECT * FROM $TBL_HOU_CATE WHERE cate_id=$cate_id";
	$result1 = mysql_query($query1) or die(mysql_error());
	$row1 = mysql_fetch_array($result1);
	$zh_cate_title1 = $row1['zh_cate_title'];
	$parent_id = $row1['parent_id'];
	$query2 = "SELECT * FROM $TBL_HOU_CATE WHERE cate_id=$parent_id";
	$result2 = mysql_query($query2) or die(mysql_error());
	$row2 = mysql_fetch_array($result2);
	$zh_cate_title2 = $row2['zh_cate_title'];
	$cate_name = $zh_cate_title2.$zh_cate_title1;
	
	$map = work_str($_POST["map"], 1);	
	
	//date_default_timezone_set('Asia/Shanghai');	
	$time=date('Y-m-d H:i:s');
    $title = work_str($_POST["title"], 1);				//房屋編號
	$address = work_str($_POST["address"], 1);		//房屋地址  
	$source = work_str($_POST["source"], 1);		//中文标题  
	$type = work_str($_POST["type"], 1);			//中文标题  
	$area = work_str($_POST["area"], 1);			//中文标题  
	$linkman = work_str($_POST["linkman"], 1);		
	$price = work_str($_POST["price"], 1);			
	$sale = work_str($_POST["sale"], 1);			
	$min_sale = work_str($_POST["min_sale"], 1);		
	$deposit = work_str($_POST["deposit"], 1);		
	$layout = work_str($_POST["layout"], 1);		
	$floor = work_str($_POST["flo1"], 1).'/'.work_str($_POST["flo2"], 1);	
	$adminnotes = work_str($_POST["adminnotes"], 1);
	$store = work_str($_POST["store"], 1);			
	$mobile = work_str($_POST["mobile"], 1);	
	$elevator = work_str($_POST["elevator"], 1);		
	$unit = work_str($_POST["unit"], 1);		
	$position = work_str($_POST["position"], 1);		
	$age = work_str($_POST["age"], 1);		
	$hit = work_str($_POST["hit"], 1);		
   	$tel = work_str($_POST["tel"], 1);					
	$featureday = work_str($_POST["featureday"], 1);			
	$feature = work_str($_POST["feature"], 1);	
	$saveplan = work_str($_POST["saveplan"], 1);	
	$recommended = work_str($_POST["recommended"], 1);
	
	$tese = work_str($_POST["tese"], 1);  //特色
	$hou_name = work_str($_POST["hou_name"], 1);  //大樓案名
	$adminshow = work_str($_POST["adminshow"], 1);  //店長推薦內容

	$sel = "select * from $TBL_HOUSE order by num desc";
	$result = mysql_query($sel);
	$row = mysql_fetch_array($result);
	if($row['num']!='')
	{
		$num = $row['num']+1;
	}else{
		$num = 10000;
	}		

	$user_id ='admin';
	$img = $_FILES['img']['name'];	
	$imgname = explode('.',$img);	
	$count = count($imgname)-1;
	$imgn = time().'.'.$imgname[$count];
	$imgn_1 = time().'_1.'.$imgname[$count];
	
    $query = "INSERT INTO $TBL_HOUSE SET cate_id='$cate_id',add_time='$time',user_id='$user_id',
	num='$num',address='$address',source='$source',type='$type',area='$area',linkman='$linkman',
	price='$price',sale='$sale',min_sale='$min_sale',deposit='$deposit',layout='$layout',floor='$floor',
	wiring='$wiring',furniture='$furniture',fire='$fire',elevator='$elevator',unit='$unit',position='$position',age='$age',tel='$tel',featureday='$featureday',feature='$feature',saveplan='$saveplan',recommended='$recommended',img='$imgn_1',hou_type=3,cate_name='$cate_name',title='$title',baohang='$baohang',baoquan='$baoquan',tese='$tese',hou_name='$hou_name',adminshow='$adminshow',map='$map',mobile='$mobile',adminnotes='$adminnotes',store='$store' ";		
    $res = mysql_query($query) or die(mysql_error());
	$insert_id = mysql_insert_id();	
	if($_FILES['img']['name']!='')
	{		
		@mkdir($conf['fck_upload'] . "house/".$insert_id);
		@chmod($conf['fck_upload'] . "house/".$insert_id,0777);	
		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$imgn;
		$upload_file = $_FILES['img']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$imgn;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$imgn_1;		
		new resizeimage($oldpic, "196", "154", "0",$newpic);//缩略圖		
	}

	if($_FILES['img1']['name']!='')
	{
		$img1 = $_FILES['img1']['name'];	
		$imgname1 = explode('.',$img1);	
		$count1 = count($imgname1)-1;
		$img1 = '1_'.time().'.'.$imgname1[$count1];
		$img1_1 ='1_'.time().'_1.'.$imgname1[$count1];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img1;
		$upload_file = $_FILES['img1']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img1;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img1_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img1='$img1_1' where id=$insert_id");
	}
	
	if($_FILES['img2']['name']!='')
	{
		$img2 = $_FILES['img2']['name'];	
		$imgname2 = explode('.',$img2);	
		$count2 = count($imgname2)-1;
		$img2 = '2_'.time().'.'.$imgname2[$count2];
		$img2_1 ='2_'.time().'_1.'.$imgname2[$count2];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img2;
		$upload_file = $_FILES['img2']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img2;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img2_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img2='$img2_1' where id=$insert_id");
	}
	
	if($_FILES['img3']['name']!='')
	{
		$img3 = $_FILES['img3']['name'];	
		$imgname3 = explode('.',$img3);	
		$count3 = count($imgname3)-1;
		$img3 = '3_'.time().'.'.$imgname3[$count3];
		$img3_1 ='3_'.time().'_1.'.$imgname3[$count3];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img3;
		$upload_file = $_FILES['img3']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img3;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img3_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img3='$img3_1' where id=$insert_id");
	}	

	if($_FILES['img4']['name']!='')
	{
		$img4 = $_FILES['img4']['name'];	
		$imgname4 = explode('.',$img4);	
		$count4 = count($imgname4)-1;
		$img4 = '4_'.time().'.'.$imgname4[$count4];
		$img4_1 ='4_'.time().'_1.'.$imgname4[$count4];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img4;
		$upload_file = $_FILES['img4']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img4;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img4_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img4='$img4_1' where id=$insert_id");
	}

	if($_FILES['img5']['name']!='')
	{
		$img5 = $_FILES['img5']['name'];	
		$imgname5 = explode('.',$img5);	
		$count5 = count($imgname5)-1;
		$img5 = '5_'.time().'.'.$imgname5[$count5];
		$img5_1 ='5_'.time().'_1.'.$imgname5[$count5];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img5;
		$upload_file = $_FILES['img5']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img5;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img5_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img5='$img5_1' where id=$insert_id");
	}

	if($_FILES['img6']['name']!='')
	{
		$img6 = $_FILES['img6']['name'];	
		$imgname6 = explode('.',$img6);	
		$count6 = count($imgname6)-1;
		$img6 = '6_'.time().'.'.$imgname6[$count6];
		$img6_1 ='6_'.time().'_1.'.$imgname6[$count6];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img6;
		$upload_file = $_FILES['img6']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img6;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img6_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img6='$img6_1' where id=$insert_id");
	}

	if($_FILES['img7']['name']!='')
	{
		$img7 = $_FILES['img7']['name'];	
		$imgname7 = explode('.',$img7);	
		$count7 = count($imgname7)-1;
		$img7 = '7_'.time().'.'.$imgname7[$count7];
		$img7_1 ='7_'.time().'_1.'.$imgname7[$count7];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img7;
		$upload_file = $_FILES['img7']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img7;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img7_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img7='$img7_1' where id=$insert_id");
	}

	if($_FILES['img8']['name']!='')
	{
		$img8 = $_FILES['img8']['name'];	
		$imgname8 = explode('.',$img8);	
		$count8 = count($imgname8)-1;
		$img8 = '8_'.time().'.'.$imgname8[$count8];
		$img8_1 ='8_'.time().'_1.'.$imgname8[$count8];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img8;
		$upload_file = $_FILES['img8']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img8;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img8_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img8='$img8_1' where id=$insert_id");
	}

	if($_FILES['img9']['name']!='')
	{
		$img9 = $_FILES['img9']['name'];	
		$imgname9 = explode('.',$img9);	
		$count9 = count($imgname9)-1;
		$img9 = '9_'.time().'.'.$imgname9[$count9];
		$img9_1 ='9_'.time().'_1.'.$imgname9[$count9];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img9;
		$upload_file = $_FILES['img9']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img9;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img9_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img9='$img9_1' where id=$insert_id");
	}

	if($_FILES['img10']['name']!='')
	{
		$img10 = $_FILES['img10']['name'];	
		$imgname10 = explode('.',$img10);	
		$count10 = count($imgname10)-1;
		$img10 = '10_'.time().'.'.$imgname10[$count10];
		$img10_1 ='10_'.time().'_1.'.$imgname10[$count10];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img10;
		$upload_file = $_FILES['img10']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img10;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img10_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img10='$img10_1' where id=$insert_id");
	}

	if($_FILES['img11']['name']!='')
	{
		$img11 = $_FILES['img11']['name'];	
		$imgname11 = explode('.',$img11);	
		$count11 = count($imgname11)-1;
		$img11 = '11_'.time().'.'.$imgname11[$count11];
		$img11_1 ='11_'.time().'_1.'.$imgname11[$count11];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img11;
		$upload_file = $_FILES['img11']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img11;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img11_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img11='$img11_1' where id=$insert_id");
	}

	if($_FILES['img12']['name']!='')
	{
		$img12 = $_FILES['img12']['name'];	
		$imgname12 = explode('.',$img12);	
		$count12 = count($imgname12)-1;
		$img12 = '12_'.time().'.'.$imgname12[$count12];
		$img12_1 ='12_'.time().'_1.'.$imgname12[$count12];

		$img_file =$conf['fck_upload'] . "house/".$insert_id;
		$file_full = $img_file."/".$img12;
		$upload_file = $_FILES['img12']['tmp_name'];          
		move_uploaded_file($upload_file, $file_full);
		$oldpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img12;
		$newpic = $img_file =$conf['fck_upload'] . "house/".$insert_id."/".$img12_1;		
		new resizeimage($oldpic, "500", "375", "0",$newpic);//缩略圖
		mysql_query("update $TBL_HOUSE SET img12='$img12_1' where id=$insert_id");
	}

	MyNotice("頂讓房添加成功", 2, "news.php");
	exit(0);

  } 

  include_once("list_cate.php");
  $time1=date('Y-m-d H:i:s');
  $tpl -> set_file(array("main" => "add_news.htm"));
  $tpl -> set_block("main","TYPE_LIST","type_list");
  
  $selxx = "select * from $TBL_OPTION order by ord asc";
	$resxx = mysql_query($selxx);
	$jj=0;
	$jd=0;
	$bh=0;
	$gs=0;
	$bq=0;
	while($rowxx = mysql_fetch_array($resxx))
	{
		if($rowxx[type]==1)//類型
		{
            $typexx = $typexx ."<input type=radio name=type value=$rowxx[title] checked >$rowxx[title]";
		}
		if($rowxx[type]==2)//電梯
		{
            $elevatorxx = $elevatorxx ."<input type=radio name=elevator value=$rowxx[title]  checked >$rowxx[title]";
		}
		if($rowxx[type]==3)//家具
		{	
			++$jj;
            $furniturexx = $furniturexx ."<input type=checkbox name=furniture$jj value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==4)//家電
		{	
			++$jd;
            $wiringxx = $wiringxx ."<input type=checkbox name=wiring$jd value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==5)//來源
		{			
            $source = $source ."<input type=radio name=source value=$rowxx[title]  checked >$rowxx[title]";
		}
		if($rowxx[type]==6)//租金包含
		{	
			++$bh;
            $baohangxx = $baohangxx ."<input type=checkbox name=baohang$bh value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==7)//公社
		{	
			++$gs;
            $firexx = $firexx ."<input type=checkbox name=fire$gs value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==8)//保全
		{	
			++$bq;
            $baoquanxx = $baoquanxx ."<input type=checkbox name=baoquan$bq value=$rowxx[title] >$rowxx[title]";
		}
		if($rowxx[type]==9)//座向
		{	
            $position = $position ."<input type=radio name=position value=$rowxx[title]  checked  >$rowxx[title]";
		}
	}
  


  $sel = "select * from $TBL_HOUSE order by num desc";
  $result = mysql_query($sel);
  $row = mysql_fetch_array($result);
  if($row['num']!='')
  {
	$num = $row['num']+1;
  }else{
	$num = 10000;
  }
  
  $selfd = "select * from $TBL_STORE order by id asc"; //分店
  $resultfd = mysql_query($selfd);
  while($rowfd = mysql_fetch_array($resultfd))
  {
		$fd  =$fd."<option value=$rowfd[id]>$rowfd[name]</option>";
  }
     //加载FCKeditor编辑器
  include($conf["base_path"] ."fckeditor/fckeditor.php");
  //中文
  $editor = new FCKeditor('tese');
  $editor -> BasePath   = "../../fckeditor/";
  $editor -> ToolbarSet = "Basic";
  $editor -> Width      = "340";
  $editor -> Height     = "200";
  $tese = $editor->CreateHtml();
  $tpl -> set_var(array(
                         "SHOW_CATE" => $show_cate,
						 "typexx" => $typexx,
						 "furniturexx" => $furniturexx,
						 "wiringxx" => $wiringxx,
						 "firexx" => $firexx,
						 "position" => $position,
						 "baohangxx" => $baohangxx,
						 "baoquanxx" => $baoquanxx,
						 "elevatorxx" => $elevatorxx,
						 "source" => $source,
						 "num" => $num,	
						 "tese" => $tese,	
					     "fd" => $fd,	  	 
                       ));
 
  $tpl->set_var($conf);
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
  exit(0);
?>